package com.oo.array_$.case_2;

/**
 * 编写JAVA程序，实现打印输出Fibonacci序列前20项的内容
 要求
 1、Fibonacci序列：前2项为1，从第三项开始，每一项等于前两项之和
 如该序列前5项为：1，1，2，3，5
 2、每输出5个数字换行显示
 *
 * @author: Jovi
 * @createTime: 2017-05-11 15:40
 **/
public class FibDemo {
    public static void main(String[] args) {
        int[] array = new int[20];
        //Save the former two data of the array
        array[0] =array[1]=1;

        //Save the data through the loop
        for (int i = 2; i < array.length; i++) {
            array[i] = array[i - 1] + array[i - 2];
        }

        //Loop output the array members
        System.out.println("Fibonacci sequence the first 20 items is：");
        for (int i = 0; i < array.length; i++) {
            if (i % 5 == 0) {
                System.out.println();
            }
            System.out.printf(array[i]+"\t");
        }
    }
}
